<%@ include file="/common/taglibs.jsp"%>

<probiz:pageHeading entityName="${giftCertificate.giftCertificateNo}"
	entityHeadingKey="giftCertificateDetail.heading" />

<content tag="buttons">
<c:choose>
	<c:when test="${empty giftCertificate.id}">
		<probiz:iconBtn btnType="save" onclick="return fnDoSave();" />
		<probiz:iconBtn btnType="saveAndSendMail" onclick="fnDoSaveAndSendEmail();" />
	</c:when>
	<c:when test="${(!empty giftCertificate.id)  and (giftCertificate.state == 0) }">
	</c:when>
	<c:when test="${(!empty giftCertificate.id)  and (giftCertificate.state == 1) }">
		<probiz:iconBtn btnType="forbid" onclick="return fnDoForbit();" />
		<probiz:iconBtn btnType="email" onclick="fnDoSendEmail();" />
	</c:when>
	<c:when test="${(!empty giftCertificate.id)  and (giftCertificate.state == 2) }">
		<probiz:iconBtn btnType="active" onclick="return fnDoActive();" />
	</c:when>
</c:choose>
<probiz:iconBtn btnType="back"
	onclick="return fnDoCancelForm(this);" />
</content>
<probiz:showBindErrors bindPath="giftCertificate.*" />

<form:form method="post" cssClass="mainForm" id="giftCertificateForm" name="giftCertificateForm"
	commandName="giftCertificate" action="${ctxPath}/sales/giftCertificate.html">
<div class="top clearfix">
	<ul class="tab">
		<li class="curr"><span><fmt:message key="giftCertificateDetail.heading"/></span></li>
	</ul>
</div>
<div class="modify">
<table class="com_modi_table" cellSpacing=0 cellPadding=0 width="100%"
	border=0>
	<tr>
		<input type="hidden" name="giftCertificateId" id="giftCertificateId" value="${giftCertificate.giftCertificateId}" />
		<th class="label_width_1">
			<StoreAdmin:label key="giftCertificate.giftCertificateNo" />
		</th>
		<td>
			<c:choose>
				<c:when test="${not empty giftCertificate.giftCertificateId}">
					${giftCertificate.giftCertificateNo}
					&nbsp;&nbsp;&nbsp;
					<b><fmt:message key="giftCertificate.sa_state.s${giftCertificate.state}" /></b>
				</c:when>
				<c:otherwise>
					<fmt:message key="giftCertificate.giftCertificateNo.readme" /> (<fmt:message key="giftCertificate.giftCertificateNo.format" />)
				</c:otherwise>
			</c:choose>
		</td>
	</tr>
	<tr>
		<th>
			<StoreAdmin:label key="giftCertificate.purchaser" />
		</th>
		<td>
			<span><form:input path="purchaser" size="32" cssClass="inputtxt"/></span> 
			<probiz:plugin_tip id="purchaserDesc"><fmt:message key="giftCertificate.purchaser.tip" /></probiz:plugin_tip>
		</td>
	</tr>
	<tr>
		<th>
			<StoreAdmin:label key="giftCertificate.recipient" />
		</th>
		<td>
			<span><form:input path="recipient" size="32"  cssClass="inputtxt"/></span> 
			<probiz:plugin_tip id="recipientDesc"><fmt:message key="giftCertificate.recipient.tip" /></probiz:plugin_tip>
		</td>
	</tr>
	<tr>
		<th>
			<StoreAdmin:label key="giftCertificate.recipientEmail" />
		</th>
		<td>
			<span><form:input path="recipientEmail" size="64"  cssClass="inputtxt"/></span> 
			<probiz:plugin_tip id="recipientEmailDesc"><fmt:message key="giftCertificate.recipientEmail.tip" /></probiz:plugin_tip>
		</td>
	</tr>
	<tr>
		<th>
			<StoreAdmin:label key="giftCertificate.message" />
		</th>
		<td>
			<textarea cols="80" rows="20" id="message" name="message" class="textareatxt">${giftCertificate.message}</textarea>
		</td>
	</tr>
	<tr>
		<th>
			<StoreAdmin:label key="giftCertificate.giftCertAmt" />
		</th>
		<td>
			<span><form:input path="giftCertAmt" size="10"  cssClass="inputtxt"/></span>
			<probiz:plugin_tip id="giftCertAmtDesc"><fmt:message key="giftCertificate.giftCertAmt.tip" /></probiz:plugin_tip>
			(<fmt:formatNumber type="currency" value="${appConfig.giftCertificateMinAmt}" pattern="${appConfig.defaultCurrencySymbol}#"/>-<fmt:formatNumber type="currency" value="${appConfig.giftCertificateMaxAmt}" pattern="${appConfig.defaultCurrencySymbol}#"/>)
		</td>
	</tr>
	<c:if test="${not empty giftCertificate.giftCertificateId}">
		<tr>
			<th>
				<StoreAdmin:label key="giftCertificate.remainedAmt" />
			</th>
			<td>
				<span><form:input path="remainedAmt" size="10"  cssClass="inputtxt"/></span>
				
			</td>
		</tr>
		<tr>
			<th>
				<StoreAdmin:label key="giftCertificate.orderNo" />
			</th>
			<td>
				<span><form:input path="orderNo" size="20"  cssClass="inputtxt"/></span>
				
			</td>
		</tr>
		<tr>
			<th>
				<StoreAdmin:label key="giftCertificate.orderNoInUse" />
			</th>
			<td>
				<span><form:input path="orderNoInUse" size="20"  cssClass="inputtxt"/></span>
				
			</td>
		</tr>
	</c:if>
	<tr>
		<th>
			<StoreAdmin:label key="giftCertificate.expireTime" />(<span class="red">*</span>)
		</th>
		<td>
			<span><form:input id="expireTime" path="expireTime"
				 cssClass="inputtxt" size="10"/></span> 
			<probiz:plugin_tip id="expireTimeDesc"><fmt:message key="giftCertificate.expireTime.tip" /></probiz:plugin_tip>
			<c:if test="${empty giftCertificate.giftCertificateId}">
				<probiz:ui_datePicker outPut="expireTime" />
			</c:if>	
		</td>
	</tr>
	
	<c:if test="${not empty giftCertificate.giftCertificateId}">
		<tr>
			<th>
				<StoreAdmin:label key="common.message.createBy" />
			</th>
			<td>
				<system:operatorUserName userId="${giftCertificate.createBy}" defaultValue="[匿名购买]"/>
			</td>
		</tr>
		<tr>
			<th>
				<StoreAdmin:label key="common.message.createTime" />
			</th>
			<td>
				<fmt:formatDate value="${giftCertificate.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
			</td>
		</tr>
		
		<tr>
			<th>
				<StoreAdmin:label key="common.message.updateTime" />
			</th>
			<td>
				<fmt:formatDate value="${giftCertificate.updateTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
			</td>
		</tr>
	</c:if>
	
	
</table>
</div>		
</form:form>

<v:javascript formName="giftCertificate" staticJavascript="false" />
<script type="text/javascript">
$j(document).ready(function () {
	__FMTExtend = {
		giftCertificate_validate_expireTimeGtNow : '<fmt:message key="giftCertificate.validate.expireTimeGtNow"/>'
	};
	$j.extend(__FMT, __FMTExtend); 
});	

$j(document).ready(function () {
	applyValidate($("giftCertAmt"),"required,minValue="+${appConfig.giftCertificateMinAmt}+",maxValue="+${appConfig.giftCertificateMaxAmt}+",integer");
	
	if(${!empty giftCertificate.giftCertificateId}){
		$j('#giftCertificateForm :input').attr("readOnly","readOnly");
	}
});	

function fnDoSendEmail(){
	document.giftCertificateForm.action += "?doAction=sendEmail";
	document.giftCertificateForm.submit();
}

function fnDoSaveAndSendEmail(){
	var confirmMsg = __FMT.common_message_confirmSaveThis+"?";
	if(validateAction()){
	    if (!confirmMsg || confirm(confirmMsg)) {
			document.giftCertificateForm.action += "?doAction=saveAndSendEmail";
			document.giftCertificateForm.submit();
		}
	}
}
function fnDoForbit(){
	document.giftCertificateForm.action += "?doAction=forbit";
	document.giftCertificateForm.submit();
}
function fnDoActive(){
	document.giftCertificateForm.action += "?doAction=active";
	document.giftCertificateForm.submit();
}

function fnDoSave(){
	var confirmMsg = __FMT.common_message_confirmSaveThis+"?";
	if(validateAction()){
    	if (!confirmMsg || confirm(confirmMsg)) {
	    	document.giftCertificateForm.action += "?doAction=save";
			document.giftCertificateForm.submit();
	    }
    }
}

function checkExpireTime(){
	var today = new Date();
	today.setHours(0);
	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);
	var expireTime = fnPaserDate($("expireTime").value);
	expireTime.setHours(0);
	expireTime.setMinutes(0);
	expireTime.setSeconds(0);
	expireTime.setMilliseconds(0);
   	if (today.getTime() >= expireTime.getTime() ){
   		$j('#expireTime').focus();
   		alert(__FMT.giftCertificate_validate_expireTimeGtNow);
   		return false;
   	}else{
   		return true;
   	}
}
function validateAction(){
	if(!checkExpireTime()){
    	return false;
   	}
	 if(!validateForm($('giftCertificateForm'))){
		alert(__vaMsg.notPass);    	
    	return false;
   	}
   	   
    return true;
}
</script>